<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml" xmlns:shiro="http://www.w3.org/1999/xhtml">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<style>
    .bootstrap-table,
    .myFull {
        width: 100%;
        height: 100%;
    }
    #editor—wrapper {
        border: 1px solid #ccc;
        z-index: 999; /* 按需定义 */
    }
    #editor—wrapper .w-e-scroll{
        overflow-y: auto;
        height: 200px;
    }
    .fixed-table-toolbar {
        height: 0px;
    }

    .fixed-table-container {
        height: calc(100% - 75px);
    }

    .fixed-table-pagination {
        height: 55px;
    }

</style>
<link href="/lib/wangeditor/css/style.css" rel="stylesheet">
<script src="/lib/wangeditor/index.js"></script>
<input id="myId" th:value="${null!=myId?myId:''}" type="hidden">
<div class="wrapper wrapper-content myFull">
    <div class="col-sm-12 nopadding myFull">
        <div class="ibox myFull">
            <div class="ibox-body myFull">
                <div class="col-sm-12 "
                     style="height: calc(100% - 160px);background-color: #fff; display: flex; align-items: center;">
                    <table id="exampleTable">
                    </table>
                </div>
                <div class="col-sm-12 "
                     style="height: 140px;margin:10px 0px;background-color: #fff; display: flex; align-items: center;justify-content: center;">
                    <button type="button" class="btn" onclick="myAudit(false,'',false)" style="margin-right: 10px;">
                        拒绝
                    </button>
                    <button type="button" class="btn  btn-primary" onclick="myAudit(true,'',true)" style="margin-left: 10px;">
                        通过
                    </button>
                </div>

            </div>
        </div>
    </div>
</div>


</div>
<div th:include="include :: footer"></div>
<script>
    $(function () {
        load();
        const checkIsFullScreen = () => {
            var isFullScreen = document.fullscreen || document.mozFullScreen || document.webkitIsFullScreen;
            return isFullScreen == undefined ? false : isFullScreen;
        }
    });



    function load() {
        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get', // 服务器数据的请求方式 get or post
                    url: "/jzweb/declareType/list", // 服务器数据的加载地址
                    //	showRefresh : true,
                    //	showToggle : true,
                    //	showColumns : true,
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: true, // 设置为true会有隔行变色效果
                    dataType: "json", // 服务器返回的数据类型
                    pagination: true, // 设置为true会在底部显示分页条
                    singleSelect: false, // 设置为true将禁止多选
                    contentType: 'application/x-www-form-urlencoded;charset=utf-8',
                    // //发送到服务器的数据编码类型
                    pageSize: 10, // 如果设置了分页，每页数据条数
                    pageNumber: 1, // 如果设置了分布，首页页码
                    //search : true, // 是否显示搜索框
                    showColumns: false, // 是否显示内容下拉框（选择显示的列）
                    sidePagination: "server", // 设置在哪里进行分页，可选值为"client" 或者 "server"
                    queryParamsType: "",
                    // //设置为limit则会发送符合RESTFull格式的参数
                    queryParams: function (params) {
                        return {
                            //说明：传入后台的参数包括offset开始索引，limit步长，sort排序列，order：desc或者,以及所有列的键值对
                            current: params.pageNumber,
                            size: params.pageSize,
                            declareId: $("#myId").val()
                        };
                    },
                    // //请求服务器数据时，你可以通过重写参数的方式添加一些额外的参数，例如 toolbar 中的参数 如果
                    // queryParamsType = 'limit' ,返回参数必须包含
                    // limit, offset, search, sort, order 否则, 需要包含:
                    // pageSize, pageNumber, searchText, sortName,
                    // sortOrder.
                    // 返回false将会终止请求
                    responseHandler: function (res) {
                        return {
                            "total": res.data.total,//总数
                            "rows": res.data.records   //数据
                        };
                    },
                    columns: [
                        {
                            field: 'type',
                            title: '类型',
                            width: 120,
                            formatter: function (value, row, index) {
                                //1.实习单位 2.优秀培训教师3.优秀考务工作者4.特殊贡献奖5.优秀案例
                                return row.type == 1 ? `<div style="width: 120px">实习单位</div>` :
                                    row.type == 2 ? `<div style="width: 120px">优秀培训教师</div>` :
                                        row.type == 3 ? `<div style="width: 120px">优秀考务工作者</div>` :
                                            row.type == 4 ? `<div style="width: 120px">优秀组织管理奖</div>` :
                                                `<div style="width: 120px">优秀案例</div>`
                            }
                        },
                        {
                            field: 'certType',
                            title: '证书类型',
                            width: 120,
                            formatter: function (value, row, index) {
                                //1=幼儿照护,2=产后恢复
                                return row.certType == 1 ? `<div style="width: 120px">幼儿照护</div>` :
                                    row.certType == 2 ? `<div style="width: 120px">产后恢复</div>` :
                                        row.certType == 0 ? `<div style="width: 120px">-</div>`:
                                                `<div style="width: 120px"></div>`
                            }
                        },
                        {
                            field: 'name',
                            title: '姓名',
                            width: 120,
                            formatter: function (value, row, index) {
                                return `<div style="width: 120px">` + row.name + `</div>`
                            }
                        },
                        {
                            field: 'card',
                            title: '身份证号码'
                        },
                        {
                            field: 'section',
                            title: '单位名称'
                        },
                        {
                            field: 'phone',
                            title: '联系方式'
                        },
                        {
                            field: 'recommendFile',
                            title: '推荐表',
                            formatter: function (value, row, index) {
                                if (null != row.declareFileDOS && '' != row.declareFileDOS) {
                                    let video = ''
                                    for (let i = 0; i < row.declareFileDOS.length; i++) {

                                        if (row.declareFileDOS[i].recommended == '0') {
                                            video = row.declareFileDOS[i].file
                                        }
                                    }
                                    video=video.substring(video.lastIndexOf('/') + 1)
                                    // video=video.substring(32)
                                    return '' != video ? `<span class="btn">` + video + `</span> ` : '-'
                                } else {
                                    return '-'
                                }

                            }
                        },
                        {
                            field: 'proofFile',
                            title: '佐证材料',
                            formatter: function (value, row, index) {
                                if (null != row.declareFileDOS && '' != row.declareFileDOS) {
                                    let video = ''
                                    for (let i = 0; i < row.declareFileDOS.length; i++) {

                                        if (row.declareFileDOS[i].recommended == '1') {
                                            video = row.declareFileDOS[i].file
                                        }
                                    }
                                    video=video.substring(video.lastIndexOf('/') + 1)
                                    // video=video.substring(32)

                                    return '' != video ? `<span class="btn">` + video + `</span> ` : '-'
                                } else {
                                    return '-'
                                }
                            }
                        },
                        {
                            field: 'video',
                            title: '视频',
                            formatter: function (value, row, index) {
                                if (null != row.declareFileDOS && '' != row.declareFileDOS) {
                                    let video = ''
                                    for (let i = 0; i < row.declareFileDOS.length; i++) {

                                        if (row.declareFileDOS[i].type == '3') {
                                            video = row.declareFileDOS[i].file
                                        }
                                    }
                                    return '' != video ? `<div style="width: 320px;height:180px;">
                                          <video  class="video-js vjs-tech video-js vjs-big-play-centered vjs-paused my-video-dimensions vjs-controls-enabled vjs-workinghover vjs-v7 vjs-user-active"
                                          preload="auto" poster="" data-setup='{}' tabindex="-1" lang="zh-cn" role="region" aria-label="视频播放器"
                                          x5-video-player-fullscreen="false"
                                          controls  id="video` + row.id + `">
                                        <source src="` + video + `" type="video/mp4">
                                        您的浏览器不支持 video 标签。
                                        </video> </div>` : '-'
                                } else {
                                    return '-'
                                }
                            }
                        },
                    ],
                    onClickCell: function (field, value, row, $element) {
                        if (field == "proofFile" ||field=='recommendFile') {
                            let declareFileId=''
                            for (let i = 0; i < row.declareFileDOS.length; i++) {
                                if (row.declareFileDOS[i].recommended == '1' && field == "proofFile") {
                                    declareFileId = row.declareFileDOS[i].id
                                }
                                if (row.declareFileDOS[i].recommended == '0' && field == "recommendFile") {
                                    declareFileId = row.declareFileDOS[i].id
                                }
                            }
                            console.log('点击', declareFileId);
                            var loading = layer.load('加载中...');
                            //获取
                            $.ajax({
                                url: "/jzweb/declareType/documentConversion",
                                type: "POST",
                                data: {
                                    resourceId: declareFileId
                                },
                                dataType: "json",
                                success: function (r) {
                                    if (r.code == '200' || r.code == 200) {
                                        if (r.data.pdfUrl) {
                                            //http只能进行下载本地临时地址访问
                                            // $.ajax({
                                            //     url: r.data.pdfUrl,
                                            //     mimeType: 'text/plain; charset=x-user-defined',
                                            //     cache: true,
                                            //     type: "GET",
                                            //     async: false,
                                            //     success: function (data) {
                                            //         layer.close(loading);
                                            //         var rawLength = data.length;
                                            //         var array = new Uint8Array(new ArrayBuffer(rawLength));
                                            //         for (i = 0; i < rawLength; i++) {
                                            //             array[i] = data.charCodeAt(i) & 0xff;
                                            //         }
                                            //         //上面是把后台请求到的文件流进行转化为符合的流
                                            //         var blob = new Blob([array], {type: 'application/pdf;charset-UTF-8'});
                                            //         let file = window.URL.createObjectURL(blob)
                                            //         layer.open({
                                            //             type: 2,
                                            //             title: '预览',
                                            //             closeBtn: 1,
                                            //             area: ['1200px', '700px'],
                                            //             fixed: false,
                                            //             maxmin: true,
                                            //             content: file
                                            //         });
                                            //
                                            //     },
                                            //     error: function (err) {
                                            //         layer.close(loading);
                                            //         console.log("错误")
                                            //     }
                                            // });
                                            layer.close(loading);
                                            layer.open({
                                                type: 2,
                                                title: '预览',
                                                closeBtn: 1,
                                                area: [ '700px', '700px' ],
                                                fixed: false,
                                                maxmin: true,
                                                content:r.data.pdfUrl
                                            });
                                        } else {
                                            layer.close(loading);
                                            layer.msg("请重试")
                                        }
                                    } else {
                                        layer.close(loading);
                                        layer.msg("暂无数据")
                                    }
                                },
                                error: function (err) {
                                    layer.close(loading);
                                }
                            });

                        }
                    }
                });
    }

    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    }

    const myAudit =  (istrue,remark,isstatus) => {
        console.log("通过==》", istrue)
        if(!istrue){
          layer.open({
                type: 1,
                area : [ '500px', '500px' ],
                resize: false,
                shadeClose: true,
                title: '审核拒绝原因',
                content: ` <div class="layui-form" style="padding: 20px;">
                                <div class="layui-form-item" style="height: 350px">
                                 <div  id="editor—wrapper">
                                  <div id="toolbar-container"><!-- 工具栏 --></div>
                                  <div id="editor-container"><!-- 编辑器 --></div>
                                  </div>
                                </div>
                                 <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" id="btn2" >确定</button>
              </div>
                           </div>`,
                success: function(){
                    let remark=''
                    $('#btn2').click(function(){
                        console.log('==remark.trim()=',remark.trim())
                        if(remark.trim()==''|| `<p><br></p>`==remark.trim()){
                            parent.layer.alert('请输入拒绝原因')
                        }else{
                            myAudit(true,remark.trim(),false)
                        }
                    })
                    //富文本
                        const {createEditor, createToolbar} = window.wangEditor
                        const editorConfig = {
                            placeholder: '请输入介绍',
                            MENU_CONF: {
                                uploadImage: {
                                    fieldName: 'file',
                                    server: '',
                                    // 自定义上传
                                    async customUpload(file, insertFn) {
                                        var formData = new FormData();
                                        formData.append('file', file);
                                        //文件上传
                                        await $.ajax({
                                            cache: false,
                                            async: true,
                                            processData: false,
                                            contentType: false,
                                            type: "POST",
                                            url: "/common/sysFile/upload",
                                            data: formData,
                                            error: (request) => {
                                                parent.layer.alert("Connection error");
                                            },
                                            success: (res) => {
                                                if (res.code == 0) {
                                                    // 最后插入图片
                                                    insertFn(res.data, '', '')
                                                } else {
                                                    parent.layer.alert(res.msg)
                                                }

                                            }
                                        });
                                    }
                                    // base64LimitSize: 10 * 1024 * 1024 // 10M 以下插入 base64
                                },
                                uploadVideo: {
                                    fieldName: 'file',
                                    server: '',
                                    // 自定义上传
                                    async customUpload(file, insertFn) {
                                        var formData = new FormData();
                                        formData.append('file', file);
                                        //文件上传
                                        await $.ajax({
                                            cache: false,
                                            async: true,
                                            processData: false,
                                            contentType: false,
                                            type: "POST",
                                            url: "/common/sysFile/upload",
                                            data: formData,
                                            error: (request) => {
                                                parent.layer.alert("Connection error");
                                            },
                                            success: (res) => {
                                                if (res.code == 0) {
                                                    // 最后插入视频
                                                    insertFn(res.data, '')
                                                } else {
                                                    parent.layer.alert(res.msg)
                                                }

                                            }
                                        });
                                    }
                                }
                            },
                            onChange(editor) {
                                remark = editor.getHtml()
                            }
                        }
                        myEditor = createEditor({
                            selector: '#editor-container',
                            html: '',
                            config: editorConfig,
                            mode: 'default', // or 'simple'
                        })
                        const toolbarConfig = {
                            toolbarKeys: [
                                "headerSelect",
                                "blockquote",
                                "|",
                                "bold",
                                "underline",
                                "italic",
                                {
                                    "key": "group-more-style",
                                    "title": "更多",
                                    "iconSvg": "<svg viewBox=\"0 0 1024 1024\"><path d=\"M204.8 505.6m-76.8 0a76.8 76.8 0 1 0 153.6 0 76.8 76.8 0 1 0-153.6 0Z\"></path><path d=\"M505.6 505.6m-76.8 0a76.8 76.8 0 1 0 153.6 0 76.8 76.8 0 1 0-153.6 0Z\"></path><path d=\"M806.4 505.6m-76.8 0a76.8 76.8 0 1 0 153.6 0 76.8 76.8 0 1 0-153.6 0Z\"></path></svg>",
                                    "menuKeys": [
                                        "through",
                                        "code",
                                        "sup",
                                        "sub",
                                        "clearStyle"
                                    ]
                                },
                                "color",
                                "bgColor",
                                "|",
                                "fontSize",
                                "fontFamily",
                                "lineHeight",
                                "|",
                                "bulletedList",
                                "numberedList",
                                "todo",
                                {
                                    "key": "group-justify",
                                    "title": "对齐",
                                    "iconSvg": "<svg viewBox=\"0 0 1024 1024\"><path d=\"M768 793.6v102.4H51.2v-102.4h716.8z m204.8-230.4v102.4H51.2v-102.4h921.6z m-204.8-230.4v102.4H51.2v-102.4h716.8zM972.8 102.4v102.4H51.2V102.4h921.6z\"></path></svg>",
                                    "menuKeys": [
                                        "justifyLeft",
                                        "justifyRight",
                                        "justifyCenter",
                                        "justifyJustify"
                                    ]
                                },
                                {
                                    "key": "group-indent",
                                    "title": "缩进",
                                    "iconSvg": "<svg viewBox=\"0 0 1024 1024\"><path d=\"M0 64h1024v128H0z m384 192h640v128H384z m0 192h640v128H384z m0 192h640v128H384zM0 832h1024v128H0z m0-128V320l256 192z\"></path></svg>",
                                    "menuKeys": [
                                        "indent",
                                        "delIndent"
                                    ]
                                },
                                "|",
                                // "emotion",
                                "insertLink",
                                {
                                    "key": "group-image",
                                    "title": "图片",
                                    "iconSvg": "<svg viewBox=\"0 0 1024 1024\"><path d=\"M959.877 128l0.123 0.123v767.775l-0.123 0.122H64.102l-0.122-0.122V128.123l0.122-0.123h895.775zM960 64H64C28.795 64 0 92.795 0 128v768c0 35.205 28.795 64 64 64h896c35.205 0 64-28.795 64-64V128c0-35.205-28.795-64-64-64zM832 288.01c0 53.023-42.988 96.01-96.01 96.01s-96.01-42.987-96.01-96.01S682.967 192 735.99 192 832 234.988 832 288.01zM896 832H128V704l224.01-384 256 320h64l224.01-192z\"></path></svg>",
                                    "menuKeys": [
                                        "insertImage",
                                        "uploadImage"
                                    ]
                                },
                                {
                                    "key": "group-video",
                                    "title": "视频",
                                    "iconSvg": "<svg viewBox=\"0 0 1024 1024\"><path d=\"M981.184 160.096C837.568 139.456 678.848 128 512 128S186.432 139.456 42.816 160.096C15.296 267.808 0 386.848 0 512s15.264 244.16 42.816 351.904C186.464 884.544 345.152 896 512 896s325.568-11.456 469.184-32.096C1008.704 756.192 1024 637.152 1024 512s-15.264-244.16-42.816-351.904zM384 704V320l320 192-320 192z\"></path></svg>",
                                    "menuKeys": [
                                        "insertVideo",
                                        "uploadVideo"
                                    ]
                                },
                                "insertTable",
                                "codeBlock",
                                "divider",
                                "undo",
                                "redo",
                                "fullScreen"
                            ]
                        }
                        const toolbar = createToolbar({
                            editor: myEditor,
                            selector: '#toolbar-container',
                            config: toolbarConfig,
                            mode: 'default', // or 'simple'
                        })

                }
            })
        }else{
            let formData = {}
            formData.toString()
            $.ajax({
                cache: true,
                type: "POST",
                url: "/jzweb/declareType/process",
                data: {
                    declareId: decodeURI($("#myId").val()),
                    status: isstatus ? 1 : 2,
                    remark: remark
                },
                async: false,
                error: function (request) {
                    parent.layer.alert("Connection error");
                },
                success: function (data) {
                    if (data.code == 0) {
                        parent.layer.msg("操作成功");
                        parent.reLoad();
                        var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                        parent.layer.close(index);

                    } else {
                        parent.layer.alert(data.msg)
                    }

                }
            });

        }

    }


</script>
</body>
</html>